<?php

namespace Xrfg\Api\Trading\Account\Resources;

use App\Http\Resources\Resource;
use Xrfg\Core\Trading\Account\Models\Coin;

class TransferResource extends Resource
{
    /**
     * Transform the resource collection into an array.
     *
     * @param \Illuminate\Http\Request $request
     *
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'user_id' => $this->user_id,
            'coin_id' => $this->coin_id,
            'coin_name' => Coin::find($this->coin_id)->name,
            'number' => $this->number,
            'from_account' => $this->from_account,
            'to_account' => $this->to_account,
            'time' => $this->time,
//            'type_text' => $this->getTypeText($request->type, $this->from_account, $this->to_account),
//            'sign' => $this->getSign($request->type, $this->from_account, $this->to_account),
            'status' => '成功'
        ];
    }

    /**
     * @param $type 划转记录类型 account:总账户 spot_account:币币账户 otc_account:法币账户 activity_account:活动账户
     * @param $from 划转自
     * @param $to 划转至
     *
     * @return string
     */
    private function getTypeText($type, $from, $to)
    {
        if ($type == $from) {
            return '转出';
        } elseif ($type == $to) {
            return '转入';
        } else {
            return '';
        }
    }

    /**
     * @param $type 划转记录类型 account:总账户 spot_account:币币账户 otc_account:法币账户 activity_account:活动账户
     * @param $from 划转自
     * @param $to 划转至
     *
     * @return string
     */
    private function getSign($type, $from, $to)
    {
        if ($type == $from) {
            return '-';
        } elseif ($type == $to) {
            return '+';
        } else {
            return '';
        }
    }
}
